$j=jQuery.noConflict();
$j(document).ready(function() {
	$j(".firmsPhoto").click(function(event){
		var lastImgName=$j(".firmsPhoto").size();
		var imgId=$j(this).attr('id');
		var imgSrc=$j(this).attr('src');
		$j(".photoFrame").html('<img class="fullImg" src="'+imgSrc+'">\
		<div class="closePhotoFrame">\
			<img src="images/closebutton.jpg" width="30" height="30">\
		</div>\
		<div class="nextPhoto">\
			<img src="images/next.png" width="40" height="40">\
		</div>\
		<div class="prevPhoto">\
			<img src="images/previous.png" width="40" height="40">\
		</div>\
		');
		$j(".photoFrame").fadeIn(500);
              if(imgId=="firmsPhoto1")$j(".prevPhoto").css("display", "none");
		if(imgId=="firmsPhoto"+lastImgName)$j(".nextPhoto").css("display", "none");
               function nextPhoto()
               {
               	$j(".prevPhoto").css("display", "block");
               	$j(".fullImg").fadeTo(100, 0.5, function(){//css("display", "none");
               	//var imgName=imgSrc.charAt(imgSrc.length-5);

               	var nextImgId=parseInt(imgId[imgId.length-1])+1;
               	var imgSrc=$j("#"+imgId).attr("src");
               	imgId="firmsPhoto"+nextImgId;
               	var imgPathEls=imgSrc.split("/");
               	var imgNameWithExt=imgPathEls[imgPathEls.length-1];
               	var imgNameEls=imgNameWithExt.split(".");
               	var imgName=imgNameEls[0];
               	delete imgPathEls[imgPathEls.length-1];
               	var imgFolder=imgPathEls.join("/");
 			var nextImgName=parseInt(imgName)+1;
			//alert(nextImgName);
			if(nextImgName==lastImgName)
			{
				$j(".nextPhoto").css("display", "none");
			}
				var nextImgSrc=$j("#"+imgId).attr("src"); //imgFolder+nextImgName+".jpg";
				$j(".fullImg").attr("src", nextImgSrc);
				imgSrc=nextImgSrc;
			$j(".fullImg").fadeTo(100, 1);
			});
               }
               function prevPhoto(){
               	$j(".nextPhoto").css("display", "block");
               	$j(".fullImg").fadeTo(100, 0.5, function(){               	var prevImgId=parseInt(imgId[imgId.length-1])-1;
               	var imgSrc=$j("#"+imgId).attr("src");
               	//alert(imgSrc);
               	imgId="firmsPhoto"+prevImgId;
               	//alert(imgId);
               	var imgPathEls=imgSrc.split("/");
               	var imgNameWithExt=imgPathEls[imgPathEls.length-1];
               	var imgNameEls=imgNameWithExt.split(".");
               	var imgName=imgNameEls[0];
               	delete imgPathEls[imgPathEls.length-1];
               	var imgFolder=imgPathEls.join("/");
               	var prevImgName=parseInt(imgName)-1;
			if(prevImgName==1)
			{
				$j(".prevPhoto").css("display", "none");
			}
			var prevImgSrc=$j("#"+imgId).attr("src");//var prevImgSrc=imgFolder+prevImgName+".jpg";
			$j(".fullImg").attr("src", prevImgSrc);
			imgSrc=prevImgSrc;
			$j(".fullImg").fadeTo(100, 1);
			});
               }
               $j(".nextPhoto").click(function(){
               	nextPhoto();
			});
		 $j(".prevPhoto").click(function(){
               	prevPhoto();
			});

		$j(".closePhotoFrame").click(function(){
			$j(".photoFrame").fadeOut(500);
		});
		});


});